package com.aidex.system.mapper;

import com.aidex.common.core.domain.entity.SysUser;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public interface SysUserMapper extends BaseMapper<SysUser> {

    @Override
    @Select("select * from sys_user t where id = #{id}")
    @Result(column = "dept_id", property = "dept", one = @One(select = "com.aidex.system.mapper.SysDeptMapper.selectById"))
    @Result(column = "dept_id", property = "deptId")
    @Result(column = "id", property = "roles", many = @Many(select = "com.aidex.system.mapper.SysRoleMapper.selectListByUserId"))
    @Result(column = "id", property = "posts", many = @Many(select = "com.aidex.system.mapper.SysPostMapper.selectListByUserId"))
    @Result(column = "id", property = "id")
    SysUser selectById(@Param("id") Serializable id);

    @Override
    @Select("select * from sys_user t ${ew.customSqlSegment}")
    @Result(column = "dept_id", property = "dept", one = @One(select = "com.aidex.system.mapper.SysDeptMapper.selectById"))
    @Result(column = "dept_id", property = "deptId")
    @Result(column = "id", property = "roles", many = @Many(select = "com.aidex.system.mapper.SysRoleMapper.selectListByUserId"))
    @Result(column = "id", property = "posts", many = @Many(select = "com.aidex.system.mapper.SysPostMapper.selectListByUserId"))
    @Result(column = "id", property = "id")
    List<SysUser> selectList(@Param("ew") Wrapper<SysUser> queryWrapper);

    @Select("select t.* from sys_user t left join sys_user_role ur on ur.user_id = t.id ${ew.customSqlSegment}")
    @Result(column = "dept_id", property = "dept", one = @One(select = "com.aidex.system.mapper.SysDeptMapper.selectById"))
    @Result(column = "dept_id", property = "deptId")
    IPage<SysUser> selectPageByRoleId(IPage<SysUser> page, @Param("ew") Wrapper<SysUser> queryWrapper);

    /**
     * 根据id集合获取用户对象
     *
     * @param idsList
     * @return
     */
    List<Map<String, Object>> getUserInfoByIds(@Param("ids") List<List<String>> idsList);

    /**
     * 获取角色下所有用户
     *
     * @param sysUser
     * @return
     */
    List<SysUser> findRoleUserList(SysUser sysUser);
}
